﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AjaxDemo.Controllers
{
    public class AjaxController : Controller
    {
        EShopV10 db = new EShopV10();
        //
        // GET: /Ajax/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetTime()
        {
            var text = DateTime.Now.ToString();
            return Content(text);
        }

        public ActionResult SearchForm()
        {
            return View();
        }
        public ActionResult Search(String Name = "")
        {
            var model = db.Products
                .Where(p => p.Name.Contains(Name))
                .ToList();
            return PartialView(model);
        }

        public ActionResult JSonSearchForm()
        {
            return View();
        }
        public ActionResult JSonSearch(String Name = "")
        {
            var model = db.Products
                .Where(p => p.Name.Contains(Name))
                .Select(p => new { p.Name, p.UnitPrice });
            return Json(model, JsonRequestBehavior.AllowGet);
        }

	}
}